<?php
include "../include/global.php";
include "../include/admin_check.php";
$xtpl = new XTemplate ("catdestinationWrite.htm");
include "setting.php";
include "../include/function.php";

$catdestination_name=formatDataForMySql($_POST['catdestination_name']);
$catdestination_position=intval($_POST['catdestination_position']);
$catdestination_isactive=intval($_POST['catdestination_isactive']);

$ID=intval(_POST('ID'));
$type=$_POST['type'];

//
$date = date("Y-m-d");
$sub_mit = $_POST['sub_mit'];
if($sub_mit=="yes"){
	if($catdestination_name==""){
		$error_catdestination_name ="Bạn phải nhập Tên <br />";
	}
	
	$str_error=$error_catdestination_name;
	if($str_error==""){
		if($type=="ADD"){	
			$sql="INSERT INTO ".pre_table."catdestination(catdestination_name, catdestination_position, catdestination_isactive, lang) 
					VALUES	('".$catdestination_name."', '".$catdestination_position."', '".$catdestination_isactive."', '".$lang."')";
			execSQL($sql);
		}else{
			$sql="UPDATE ".pre_table."catdestination SET 
						catdestination_name='".$catdestination_name."', 
						catdestination_position='".$catdestination_position."', 
						catdestination_isactive='".$catdestination_isactive."',
						lang='".$lang."'
						WHERE catdestination_id='".$ID."'";			
			execSQL($sql);
		}			

		$act = $_POST['act'];
		if($act=='save'){
			echo '<script>
				parent.document.frmData.target = "_parent";				
				parent.window.location.href="catdestination.php";
			</script>';
		}else{	
			echo '<script>
				parent.document.frmData.target = "_parent";	
				parent.document.frmData.catdestination_name.focus();			
				parent.window.location.href="catdestinationWrite.php";
			</script>';
		}	
		
	}else{
		echo '<script>
				parent.document.frmData.target = "_parent";		
				parent.document.getElementById("err").style.display="block";
				parent.document.getElementById("err_string").innerHTML="'.$str_error.'";
			</script>';	
	}
}
?>